#pragma once
#include <string>
#include <jwt.h>

// gcc main.c -o main -lssl -lcrypto
// g++ *.cpp -o main -lssl -lcrypto -ljwt -lworkflow

class CryptoUtil
{
public:
    static std::string generate_salt(int length = 8);
    static std::string hash_password(std::string& password, std::string& salt);
    static std::string generate_token(const std::string& username);
    static bool verify_token(const std::string& token, std::string& username);

    // jwt: Header.Payload.Signature
    // Header: {"alg":"HS256", "typ":"JWT"}
    // Payload: {"username":"xjh", "sub":"upload", "role":leader, "exp":1500}
    // Signature: 
    static std::string generate_jwt_token(const char* secret_key);
    static bool verify_jwt(const char* token, const char* secret_key);
private:
    /* 禁止构造对象 */
    CryptoUtil() = delete;
};

